package com.group1.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;

public class IkUtil {
    public static ArrayList<String> split(String keywords) {

        HashSet<String> set = new HashSet<>();
        StringReader stringReader = new StringReader(keywords);
        IKSegmenter ikSegmenter = new IKSegmenter(stringReader,true);

        try {
            Lexeme next = ikSegmenter.next();

            while (next!=null){
                String word = next.getLexemeText();
                set.add(word);
                next=ikSegmenter.next();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        ArrayList<String> words = new ArrayList<>();
        words.addAll(set);
        return words;
    }
}
